/* eslint-disable */
const path = require('path')
const webpack = require('webpack')
const BASE = require('./src/config/index')
const SETTING = require('./src/config/settings')

function resolve(dir) {
  return path.join(__dirname, dir)
}

function addStyleResource(rule) {
  rule
    .use('style-resource')
    .loader('style-resources-loader')
    .options({
      // 需要引入的公共文件
      patterns: [path.resolve(__dirname, './src/assets/styles/index.less')]
    })
}

// If your port is set to 80,
// use administrator privileges to execute the command line.
// For example, Mac: sudo npm run

// All configuration item explanations can be find in https://cli.vuejs.org/config/
module.exports = {
  publicPath: './',
  outputDir: 'dist/',
  assetsDir: 'static',
  lintOnSave: true,
  productionSourceMap: false,

  css: {
    requireModuleExtension: true,
    loaderOptions: {
      postcss: {
        plugins: [
          require('postcss-pxtorem')({
            rootValue: 39,
            propList: ['*']
          })
        ]
      }
    }
  },
  devServer: {
    publicPath: '/',
    port: '8080',
    open: true,
    disableHostCheck: true,
    overlay: {
      warnings: false,
      errors: true
    },
    proxy: {
      // 以下配置建议不更改
      '/data-dict/app': {
        target: ' https://qmpdev.quanyou.com.cn/data-dict',
        changeOrigin: true,
        pathRewrite: {
          '^/data-dict/app': '/app'
        }
      },
      '/select-service/api': {
        target: 'http://select-service.itdev2.quanyou.com.cn',
        changeOrigin: true,
        pathRewrite: {
          '^/select-service/api': '/api'
        }
      },
       // qup获取权限
       '/qmp/app': {
        target: 'https://qmpdev.quanyou.com.cn/qmp',
        changeOrigin: true,
        pathRewrite: {
          '^/qmp/app': '/app'
        }
      },

      ['/'+SETTING.programmeFlag+'/app/']: {
        target: BASE.baseUrl, // 测试环境
        changeOrigin: true,
        pathRewrite: {
          ['^/' + SETTING.programmeFlag+'/app']: '/app'
        }
      },
      '/pdf-file': {
        target: 'https://filedev.quanyou.com.cn',
        changeOrigin: true,
        pathRewrite: {
          '^/pdf-file': '/'
        }
      },
    }
    // https: true
    // compress: true,
    // disableHostCheck: true
  },

  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    plugins: [
      new webpack.DefinePlugin({
        'process.env': {
          QMP_EVN: JSON.stringify(process.env.QMP_EVN)
        }
      })
    ],
    performance: {
      hints: 'warning',
      // 入口起点的最大体积
      maxEntrypointSize: 50000000,
      // 生成文件的最大体积
      maxAssetSize: 30000000,
      // 只给出 js 文件的性能提示
      assetFilter: function (assetFilename) {
        return assetFilename.endsWith('.js')
      }
    },
    name: SETTING.title,
    resolve: {
      alias: {
        '@': resolve('src')
      }
    },
    externals: {
      //   BMap: 'BMap'
    }
  },
  chainWebpack: (config) => {
    const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
    types.forEach((type) => addStyleResource(config.module.rule('less').oneOf(type)))
  }
}
